package com.work.utils;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.TimeZone;
import java.util.zip.GZIPInputStream;

import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.EntityUtils;
import org.apache.log4j.Logger;

import com.alibaba.fastjson.JSONArray;
import com.common.dto.Playinfo;


/**
 * 
 * 抓取工具类
 * 
 * @author Administrator
 * 
 */
public class HttpUtil {

	private static Logger log = Logger.getLogger("myLjTestLog");
	
	/**
	 * 获取httpget
	 * @param path
	 * @return
	 */
	public static HttpGet getHttpGet(String path){
		HttpGet httpGet = new HttpGet(path);
		setHeader(httpGet);
		return httpGet;
	}
	
	
	/**
	 * 获取HttpPost
	 * @param path
	 * @return
	 */
	public static HttpPost getHttpPost(String path){
		HttpPost httpPost = new HttpPost(path);
		setHeader(httpPost);
		return httpPost;
	}
	

	/**
	 * 设置header
	 * 
	 * @param url
	 * @param httpGet
	 */
	public static void setHeader(HttpGet httpGet) {
		httpGet.setHeader("Accept-Encoding", "gzip, deflate");
		httpGet.setHeader("Accept-Language", "zh-cn");
		httpGet.setHeader("Content-Type", "application/x-www-form-urlencoded");
		httpGet.setHeader("Accept", "application/x-shockwave-flash, image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, application/msword, application/vnd.ms-excel, application/vnd.ms-powerpoint, */*");
		httpGet.setHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1)");
		httpGet.setHeader("Connection", "Keep-Alive");
		httpGet.setHeader("Cache-Control", "no-cache");
	}

	/**
	 * 设置header
	 * 
	 * @param url
	 * @param httpPost
	 */
	public static void setHeader(HttpPost httpPost) {
		httpPost.setHeader("Accept-Encoding", "gzip, deflate");
		httpPost.setHeader("Accept-Language", "zh-cn");
		httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded");
		httpPost.setHeader("Accept", "application/x-shockwave-flash, image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, application/msword, application/vnd.ms-excel, application/vnd.ms-powerpoint, */*");
		httpPost.setHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1)");
		httpPost.setHeader("Connection", "Keep-Alive");
		httpPost.setHeader("Cache-Control", "no-cache");
	}

	/**
	 * 获得文本
	 * 
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public static String getHttpContext(HttpResponse response) throws Exception {
		long startTime = System.currentTimeMillis();
		String ret = "";

		if (response == null) {
			return ret;
		}

		HttpEntity httpEntity = response.getEntity();

		if (httpEntity == null) {
			return ret;
		}

		Header header = httpEntity.getContentEncoding();
		if (header != null) {
			if (header.getValue().contains("gzip")) {
				ret = HttpUtil.getZipContext(httpEntity.getContent());
			} else {
				ret = HttpUtil.getContext(httpEntity);
			}
		} else {
			ret = HttpUtil.getContext(httpEntity);
		}

		long endTime = System.currentTimeMillis();
		return ret;
	}

	/**
	 * 获得文本
	 * 
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public static String getHttpContextWithEnter(HttpResponse response) throws Exception {
		long startTime = System.currentTimeMillis();
		String ret = "";

		if (response == null) {
			return ret;
		}

		HttpEntity httpEntity = response.getEntity();

		if (httpEntity == null) {
			return ret;
		}

		Header header = httpEntity.getContentEncoding();
		if (header != null) {
			if (header.getValue().contains("gzip")) {
				ret = HttpUtil.getZipContext(httpEntity.getContent());
			} else {
				ret = HttpUtil.getContextWithEnter(httpEntity);
			}
		} else {
			ret = HttpUtil.getContextWithEnter(httpEntity);
		}

		long endTime = System.currentTimeMillis();
		log.info("获取数据花费：" + (endTime - startTime) + "毫秒");

		return ret;
	}
	
	

	/**
	 * 执行访问
	 * 
	 * @param httpClient
	 * @param httpGet
	 * @param localContext
	 * @return
	 * @throws Exception
	 */
	public static HttpResponse execute(DefaultHttpClient httpClient, HttpGet httpGet, HttpContext localContext) throws Exception {
		if (httpClient == null || httpGet == null || localContext == null) {
			throw new Exception("参数错误.");
		}

		try {
			long startTime = System.currentTimeMillis();

			HttpResponse httpResponse = httpClient.execute(httpGet, localContext);

			long endTime = System.currentTimeMillis();
			//bobo 
			log.info("执行请求花费：" + (endTime - startTime) + "毫秒");

			return httpResponse;
		} catch (Exception e) {
			if (e instanceof IllegalStateException) {
				httpGet.abort();
			}
			throw e;
		}
	}

	/**
	 * 执行访问
	 * 
	 * @param httpClient
	 * @param httpGet
	 * @param localContext
	 * @return
	 * @throws Exception
	 */
	public static HttpResponse execute(DefaultHttpClient httpClient, HttpPost httpPost, HttpContext localContext) throws Exception {
		if (httpClient == null || httpPost == null || localContext == null) {
			throw new Exception("参数错误.");
		}

		try {
			long startTime = System.currentTimeMillis();

			HttpResponse httpResponse = httpClient.execute(httpPost, localContext);

			long endTime = System.currentTimeMillis();
			log.info("执行请求花费：" + (endTime - startTime) + "毫秒");

			return httpResponse;
		} catch (Exception e) {
			if (e instanceof IllegalStateException) {
				httpPost.abort();
			}
			throw e;
		}
	}

	/**
	 * 去掉主机后面的/
	 * 
	 * @param url
	 * @return
	 */
	public static String dealHost(String url) {
		if (url.endsWith("/")) {
			url = url.substring(0, url.length() - 1);
		}

		return url;
	}

	/**
	 * 获得域名-www.xxx.com
	 * 
	 * @param url
	 * @return
	 */
	public static String getPurceHost(String url) {
		url = dealHost(url);

		String http = "http://";
		String https = "https://";
		if (url.startsWith(http)) {
			url = url.substring(http.length());
		} else if (url.startsWith(https)) {
			url = url.substring(https.length());
		}

		if (url.contains(":")) {
			return url.split(":")[0];
		}

		return url;
	}

	/**
	 * 获得短域名- xxx.com
	 * 
	 * @param url
	 * @return
	 */
	public static String getShortDomainName(String url) {
		String domainName = getPurceHost(url);

		String sign = "www.";
		if (domainName.startsWith(sign)) {
			domainName = domainName.substring(sign.length());
		}

		return domainName;
	}

	/**
	 * 通过数组的位置查找string数据
	 * 
	 * @param jsonArray
	 * @param valueIndexes
	 * @return
	 */
	public static String getJsonArrayStringValue(JSONArray jsonArray, Integer[] valueIndexes) {
		for (Integer i = 0; i < valueIndexes.length; i++) {
			Integer valueIndex = valueIndexes[i];
			if (valueIndex >= jsonArray.size()) {
				break;
			}
			if (i == valueIndexes.length - 1) {
				return jsonArray.getString(valueIndex);
			}
			jsonArray = getJsonArray(jsonArray, valueIndex);
			if (jsonArray == null) {
				break;
			}
		}
		return null;
	}
	
	/**
	 * 通过数组的位置查找string数据
	 * 
	 * @param jsonArray
	 * @param valueIndexes
	 * @return
	 */
	public static String getJsonArrayStringShift(JSONArray jsonArray, Integer[] valueIndexes,int shift) {
		for (Integer i = 0; i < valueIndexes.length; i++) {
			Integer valueIndex = valueIndexes[i];
			if (valueIndex+shift >= jsonArray.size()) {
				break;
			}
			if (i == valueIndexes.length - 1) {
				return jsonArray.getString(valueIndex+shift);
			}
			jsonArray = getJsonArray(jsonArray, valueIndex+shift);
			if (jsonArray == null) {
				break;
			}
		}
		return null;
	}
	
	/**
	 * 通过数组的位置查找double数据
	 * 
	 * @param jsonArray
	 * @param valueIndexes
	 * @return
	 */
	public static double getJsonArrayDoubleValue(JSONArray jsonArray, Integer[] valueIndexes) {
		String doubStr = getJsonArrayStringValue(jsonArray, valueIndexes);
		if (!isNull(doubStr)) {
			return Double.valueOf(doubStr);
		}
		return 0;
	}
	
	/**
	 * 通过数组的位置查找double数据
	 * 
	 * @param jsonArray
	 * @param valueIndexes
	 * @return
	 */
	public static double getJsonArrayDoubleShift(JSONArray jsonArray, Integer[] valueIndexes,int shift) {
		String doubStr = getJsonArrayStringShift(jsonArray, valueIndexes,shift);
		if (!isNull(doubStr)) {
			return Double.valueOf(doubStr);
		}
		return 0;
	}

	/**
	 * 通过数组的位置查找int数据
	 * 
	 * @param jsonArray
	 * @param valueIndexes
	 * @return
	 */
	public static int getJsonArrayIntValue(JSONArray jsonArray, Integer[] valueIndexes) {
		String intStr = getJsonArrayStringValue(jsonArray, valueIndexes);
		if (!isNull(intStr)) {
			return Integer.valueOf(intStr);
		}
		return 0;
	}
	
	/**
	 * 通过数组的位置查找int数据
	 * 
	 * @param jsonArray
	 * @param valueIndexes
	 * @return
	 */
	public static int getJsonArrayIntShift(JSONArray jsonArray, Integer[] valueIndexes,int shift) {
		String intStr = getJsonArrayStringShift(jsonArray, valueIndexes,shift);
		if (!isNull(intStr)) {
			return Integer.valueOf(intStr);
		}
		return 0;
	}

	/**
	 * 获取子数组
	 * 
	 * @param jsonArray
	 * @param index
	 * @return
	 */
	public static JSONArray getJsonArray(JSONArray jsonArray, Integer index) {
		Object o = jsonArray.get(index);
		if (o != null && o instanceof JSONArray) {
			return (JSONArray) o;
		}
		return null;
	}

	/**
	 * 获取子数组
	 * 
	 * @param jsonArray
	 * @param indexes
	 * @return
	 */
	public static JSONArray getJsonArray(JSONArray jsonArray, Integer[] indexes) {
		for (Integer i = 0; i < indexes.length; i++) {
			Integer valueIndex = indexes[i];
			if (i == indexes.length - 1) {
				return jsonArray.getJSONArray(valueIndex);
			}
			jsonArray = getJsonArray(jsonArray, valueIndex);
			if (jsonArray == null) {
				break;
			}
		}
		return null;
	}

	/**
	 * 转换字符
	 * 
	 * @param unicode
	 * @return
	 */
	public static String unicode2Ascii(String unicode) {
		if (unicode == null) {
			return null;
		}
		// StringTokenizer tokens = new StringTokenizer(unicode, ";");
		// StringBuilder result = new StringBuilder();
		// while (tokens.hasMoreTokens()) {
		// String token = tokens.nextToken();
		// if (token.startsWith("&#")) {
		// result.append((char) Integer.parseInt(token.substring(2)));
		// } else {
		// result.append(token);
		// }
		// }
		// return result.toString();

		return HtmlDecoder.decode(unicode);
	}

	/**
	 * 判断赛事名称是否需要替换空格
	 * 
	 * @param str
	 * @return
	 */
	public static boolean isNeedReplaceBlank(String str) {
		boolean ret = false;

		if (isNull(str)) {
			return ret;
		}

		// // 判断是否全部为英文或数字或空格
		// ret = !str.matches("^[a-zA-Z0-9 ]*");

		// 只要有一个空格两边的是英文或数字就不需要替换
		ret = blankPro(str);

		return ret;
	}

	/**
	 * 判断字符串中的空格的属性,需要替换时返回true,不需要替换时返回false;
	 * 
	 * @param str
	 * @return
	 */
	public static boolean blankPro(String str) {
		if (str == null) {
			return false;
		}

		str = str.trim();
		String blank = " ";
		String matchStr = "^[a-zA-Z0-9 ]*";

		if (str.contains(blank)) {
			int blankPos = str.indexOf(blank);
			String beforeBlank = str.substring(blankPos - 1, blankPos);
			String afterBlank = str.substring(blankPos + 1, blankPos + 2);

			if (beforeBlank.matches(matchStr) && afterBlank.matches(matchStr)) {
				return false;
			}

			return blankPro(str.substring(blankPos));
		}

		return true;
	}

	/**
	 * 替换空格
	 * 
	 * @param str
	 * @return
	 */
	public static String replaceAllBlank(String str) {
		String ret = str;
		if (!isNull(ret)) {
			ret = ret.replaceAll(" ", "");
		}

		return ret;
	}

	/**
	 * 根据流获得响应文本 gzip换行
	 * 
	 * @param is
	 * @return
	 * @throws IOException
	 */
	public static String getZipContext(InputStream is) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(new GZIPInputStream(is), "utf-8"));

		if (br != null) {
			String line = "";
			StringBuffer buffer = new StringBuffer();
			while ((line = br.readLine()) != null) {
				buffer.append(line).append("\n");
			}

			br.close();

			if (is != null) {
				is.close();
			}

			return buffer.toString();
		}

		return "";
	}

	/**
	 * 根据实体获得响应文本 换行
	 * 
	 * @param httpEntity
	 * @return
	 * @throws IOException
	 */
	public static String getContext(HttpEntity httpEntity) throws IOException {
		if (httpEntity == null) {
			return null;
		}

		return EntityUtils.toString(httpEntity, "utf-8");
	}

	/**
	 * 根据流获得响应文本 换行
	 * 
	 * @param is
	 * @return
	 * @throws IOException
	 */
	public static String getContextWithEnter(HttpEntity httpEntity) throws IOException {
		if (httpEntity == null) {
			return "";
		}

		InputStreamReader isr = new InputStreamReader(httpEntity.getContent(), "utf-8");
		BufferedReader br = new BufferedReader(isr);
		String line = "";
		StringBuffer buffer = new StringBuffer();
		while ((line = br.readLine()) != null) {
			buffer.append(line).append("\n");
		}

		if (isr != null) {
			isr.close();
		}

		if (br != null) {
			br.close();
		}

		return buffer.toString();
	}

	/**
	 * 根据流获得响应文本 换行
	 * 
	 * @param is
	 * @return
	 * @throws IOException
	 */
	public static String getContextWithEnterForTest(InputStream is) throws IOException {
		InputStreamReader isr = new InputStreamReader(is, "gbk");
		BufferedReader br = new BufferedReader(isr);
		String line = "";
		StringBuffer buffer = new StringBuffer();
		while ((line = br.readLine()) != null) {
			buffer.append(line).append("\n");
		}

		if (isr != null) {
			isr.close();
		}

		if (br != null) {
			br.close();
		}

		return buffer.toString();
	}

	/**
	 * 获得验证码的字节数组
	 * 
	 * @param is
	 * @param length
	 * @return
	 * @throws IOException
	 */
	public static byte[] getImgStr(InputStream is, int length) throws IOException {
		byte[] ret = null;
		BufferedInputStream bis = null;
		try {
			bis = new BufferedInputStream(is);
			if (length > 0) {
				byte[] buffer = new byte[1024];
				byte[] in_b = new byte[length]; // 用于存放结果的数组
				int count = 0;
				int rbyte = 0;
				// 获得响应流
				while (count < length) { // 循环读取
					rbyte = bis.read(buffer); // 每次实际读取长度存于rbyte中
					if (rbyte == -1) {
						break;
					}
					if (rbyte > length)
						rbyte = length;
					// 放到最终的结果数组中
					for (int i = 0; i < rbyte; i++) {
						in_b[count + i] = buffer[i];
					}
					count += rbyte;
				}
				ret = in_b;
			} else {
				StringBuffer sb1 = new StringBuffer();
				for (;;) {
					int data = bis.read();
					if (data == -1) {
						break;
					} else {
						sb1.append((char) data);
					}
				}
				ret = sb1.toString().getBytes();
			}

			return ret;
		} finally {
			if (bis != null)
				bis.close();
		}
	}

	/***
	 * 写byte数据方法.通用方法
	 * 
	 * @param bytes
	 *            要写的byte数组
	 * @param fileName
	 *            文件名
	 */
	public static void writeToBytes(byte bytes[], String fileName) {
		FileOutputStream fos = null;
		try {
			File file = new File(fileName);

			boolean result = false;
			if (file.exists()) {
				result = file.delete();
			} else {
				result = true;
			}

			if (result) {
				fos = new FileOutputStream(fileName, true);
				fos.write(bytes);
				fos.flush();
			}

		} catch (Exception e) {
			e.printStackTrace();

		} finally {
			try {
				if (fos != null) {
					fos.close();
				}
			} catch (IOException iex) {
			}
		}
	}

	

	/**
	 * 判断字符串是否为空
	 * 
	 * @param str
	 * @return
	 */
	public static boolean isNull(String str) {
		if (str == null || "".equals(str) || "null".equals(str)) {
			return true;
		}
		return false;
	}

	/**
	 * 处理抓取时间,抓取时间为GMT
	 * 
	 * @param oldStr
	 * @return
	 */
	public static String dealSnatchTime(String oldStr) {
		return formatSnatchTime(parseSnatchTime(oldStr));
	}

	/**
	 * 格式化抓取时间,抓取时间为GMT
	 * 
	 * @param date
	 * @return
	 */
	public static String formatSnatchTime(Date date) {
		if (date == null) {
			return "";
		}

		// 设置获取时间为GMT
		DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));

		return dateFormat.format(date);
	}

	/**
	 * 获取玩法信息map
	 * 
	 * @param playinfos
	 * @return
	 */
	public static Map<String, Playinfo> getPlayinfoMap(List<Playinfo> playinfos) {
		Map<String, Playinfo> map = new HashMap<String, Playinfo>();

		if (playinfos != null) {
			String key = "";
			for (Playinfo playinfo : playinfos) {
				key = playinfo.getGametime() + "_" + playinfo.getName();
				map.put(key, playinfo);
			}
		}

		return map;
	}

	/**
	 * 解析抓取时间,抓取时间为GMT
	 * 
	 * @param dateStr
	 * @return
	 */
	public static Date parseSnatchTime(String dateStr) {
		if (isNull(dateStr)) {
			return null;
		}

		dateStr = replaceEngMonth(dateStr);

		// 设置获取时间为GMT
		DateFormat dateFormat = new SimpleDateFormat("E, dd MM yyyy HH:mm:ss z", Locale.ENGLISH);
		dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
		try {
			return dateFormat.parse(dateStr);
		} catch (Exception e) {
			return null;
		}
	}

	/**
	 * 替换字符串中的英文月份
	 * 
	 * @param engMonthStr
	 * @return
	 */
	private static String replaceEngMonth(String engMonthStr) {
		String[] engMonths = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
		String[] months = { "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12" };

		for (int i = 0; i < months.length; i++) {
			engMonthStr = engMonthStr.replaceAll(engMonths[i], months[i]);
		}

		return engMonthStr;
	}

	

	/**
	 * 判断字符串是否为0
	 * 
	 * @param allowNum
	 * @return
	 */
	public static boolean isZeroRatio(String allowNum) {
		boolean ret = false;

		if (!isNull(allowNum)) {
			if (!allowNum.contains("-")) {
				double num = Double.valueOf(allowNum);
				if (num == 0) {
					ret = true;
				}
			}
		}

		return ret;
	}

	/**
	 * 获得本地时区
	 * 
	 * @return
	 */
	public static TimeZone getLocalTimeZone() {
		return Calendar.getInstance().getTimeZone();
	}

	/**
	 * 处理名称
	 * 
	 * @param name
	 * @return
	 */
	public static String dealName(String name) {
		String ret = name;

		if (HttpUtil.isNull(ret)) {
			return ret;
		}
		
		
		ret = ret.replaceAll("&zwnj;", "");
		// 转义
		ret = HttpUtil.unicode2Ascii(ret);
		// 去掉*
		ret = ret.replaceAll("\\*", "");
		// 去掉\r\n
		ret = ret.replaceAll("\r\n", "");
		// 去掉空格
		if (HttpUtil.isNeedReplaceBlank(ret)) {
			ret = HttpUtil.replaceAllBlank(ret);
		}

		return ret;
	}
	
	public static String blockingName(String s,String c,String e ){
		if (HttpUtil.isNull(s)) {
			return s;
		}
		if(s.contains(c)){
			s = s.substring(0,s.indexOf(e));
		}
		return s;
	}

	
	/**
	 * 获得所有的联赛id列表
	 * 
	 * @param ratioDataInput
	 * @return
	 *//*
	private static List<String> getAllLeaguesidList(RatioDataInput ratioDataInput) {
		List<String> leaguesList = new ArrayList<String>();

		if (ratioDataInput != null) {
			List<Sportinfo> sportinfos = ratioDataInput.getSportinfos();
			if (sportinfos != null) {
				for (Sportinfo sportinfo : sportinfos) {
					leaguesList.add(sportinfo.getSelfID());
				}
			}
		}

		return leaguesList;
	}*/

	/**
	 * 获得所有的联赛id列表
	 * 
	 * @param ratioDataInput
	 * @return
	 *//*
	public static String getAllLeaguesid(RatioDataInput ratioDataInput) {
		List<String> leaguesList = getAllLeaguesidList(ratioDataInput);

		String leagues = "";

		if (leaguesList != null) {
			for (String league : leaguesList) {
				leagues += league + ",";
			}
		}

		return leagues;
	}

	*//**
	 * 获得部分的联赛id列表
	 * 
	 * @param ratioDataInput
	 * @return
	 *//*
	public static String getPartLeaguesid(RatioDataInput ratioDataInput, int num) {
		List<String> leaguesList = getAllLeaguesidList(ratioDataInput);

		String leagues = "";

		if (leaguesList != null) {
			int count = num < leaguesList.size() ? num : leaguesList.size();

			for (int i = 0; i < count; i++) {
				leagues += leaguesList.get(i) + ",";
			}
		}

		return leagues;
	}
*/
	
	
	public static void main(String[] args) {
		// System.out.println(isNeedReplaceBlank("WORLD CUP 2014 ASIS QUALIFIERS SPECIALS"));
		// System.out.println(isNeedReplaceBlank("我是 U17 sww"));
		// System.out.println(isNeedReplaceBlank("WORLD CUP 2014 ASIS QUALIFIERS SPECIALS"));
		// System.out.println(isNeedReplaceBlank("我是 U17 sww"));
		// System.out.println(isNeedReplaceBlank("我是 U17"));
		// System.out.println(isNeedReplaceBlank("我是 在家"));
		// System.err.println(replaceAllBlank("在家枯* df "));
		// System.out.println(HtmlDecoder.decode("&#20122;&#27954;&#30424;"));

		// File file = new File("d://aa1.txt");
		//
		// FileInputStream is;
		// String dataContext = "";
		// try {
		// is = new FileInputStream(file);
		// dataContext = Utility.getContextWithEnterForTest(is);
		//
		// System.out.println(dataContext);
		//
		// if (is != null) {
		// is.close();
		// }
		// } catch (Exception e) {
		// e.printStackTrace();
		// }
		//
		// System.out.println(dataContext.length());
		// System.out.println(SystemUtil.gZip(dataContext).length());

		/*Calendar calendar = Calendar.getInstance();
		calendar.setTimeInMillis(635206674608430000L);
		System.out.println(calendar.getTime());
		System.out.println(System.currentTimeMillis());*/
		String str = "高科曼谷市<font color=gray> - (第4节)</font>";
		// XStream xs = new XStream();
		// RatioDataInput ratioDataInput = new RatioDataInput();
		// StringReader stringReader = new StringReader(dataContext);
		// xs.alias("RatioDataInput", RatioDataInput.class);
		// xs.alias("Sportinfo", Sportinfo.class);
		// xs.alias("Match", Match.class);
		// xs.alias("Playinfo", Playinfo.class);
		// xs.alias("TradingItem", TradingItem.class);
		// xs.fromXML(stringReader, ratioDataInput);
		//
		// System.out.println(ratioDataInput);
	}
}
